home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 004a / type_.zip / TT2.TXT < prev   
Text File  |  1980-01-01  |  9KB  |  423 lines

  1. ;
  2. ;calculate wpm for the game
  3. ;
  4. wpm        proc
  5. ;        assume    cs:codesg,ds:datasg,es:nothing
  6.         ;
  7.         ;first get a clock tick
  8.         ;
  9.         call    clock
  10.         sub    bx,gamtim[+2]
  11.         mov    gamtim[+2],bx
  12.         sbb    cx,gamtim
  13.         ;
  14.         cmp    cx,0        ;don't calculate if user has
  15.         je    okwpm        ;waited longer than 1 minute to
  16.         mov    ax,0        ;get here ... should be impossible,
  17.         jmp    wpm_exit    ;... meaning a programming error
  18.  
  19. okwpm:        cmp    gamtim[+2],0
  20.         je    wpm_exit2
  21.  
  22.         mov    ax,gamcharcnt    ;wpm = 0 if no characters typed
  23.         cmp    ax,0
  24.         je    wpm_exit
  25.         ;
  26.         mul    word ptr n1200    ;1,200 = ((60 secs/min)
  27.                     ;    X (100 ticks/sec)
  28.                     ;    / (5 chars/word)
  29. under120:    div    word ptr gamtim[+2] ; / 100ths of a second = chars/min
  30. wpm_exit:    mov    gamewpm,ax
  31. wpm_exit2:    mov    gamcharcnt,0
  32.         call    clock
  33.         mov    gamtim[+2],bx
  34.         mov    gamtim,cx
  35.         ret
  36. wpm        endp
  37. ;
  38. ;evaluate routine follows
  39. ;
  40. ;include        evaluate.asm
  41. ;************************************************************************
  42. ;* FUNCTION: XYCalc()                            *
  43. ;*                                    *
  44. ;* PARAMETERS:                                *
  45. ;*    Dx - X position on screen. (0..319)                *
  46. ;*    Di - Y position on screen. (0..199)                *
  47. ;*                                    *
  48. ;* DESCRIPTION: Calculates byte address of X, Y.  Result is in Di, Dx    *
  49. ;*        where Di is current line address of RowTable and Dx is    *
  50. ;*        the X byte offset.                    *
  51. ;************************************************************************
  52.  
  53. XYCalc_     PROC    NEAR
  54.  
  55.     Mov    Es,VideoSeg
  56.  
  57.     Shr    Dx,1
  58.     Shr    Dx,1
  59.     shr    dx,1    ;for 40 col modes
  60.  
  61.     Shl    Di,1
  62.     Lea    Di,RowTable[Di]
  63.     Ret
  64.  
  65. XYCalc_     ENDP
  66. ;************************************************************************
  67. ;* FUNCTION: PrintAt  ( X, Y, Str )                    *
  68. ;*                                    *
  69. ;* PARAMETERS:                                *
  70. ;*    X   - X position of string.  0..319 is really 0..79.        *
  71. ;*    Y   - Y position of string.  0..199                *
  72. ;*    Str - Points to the string we are to print.            *
  73. ;*                                    *
  74. ;* DESCRIPTION: Prints a string at the given coordinates.        *
  75. ;************************************************************************
  76.  
  77. PrintAt_    PROC  NEAR
  78.  
  79. ;    Mov    Bx,Sp        ;Set Bx to base of parms.
  80. ;
  81.     shl    dx,1    ;<-test
  82.     shl    dx,1    ;""
  83.     shl    dx,1    ;""
  84.     shl    dx,1
  85.     mul    byte ptr eight ;""
  86.  
  87.     Push    Si
  88.     jmp    getch
  89.     db    'uku'
  90. ;    Mov    Dx,2[Bx]    ;Get X
  91. ;    Mov    Ax,4[Bx]    ;Get Y
  92. ;    Mov    Si,6[Bx]    ;Get char pointer
  93.  
  94. GetCh:                ;WHILE ( *Pt )
  95.                 ;   BEGIN
  96.     Xor    Ch,Ch        ;   Make sure Ch is 0
  97.     Mov    Cl,[Si]     ;   Acquire the next char to draw
  98.     Jcxz    ExitPrintAt    ;   Exit if we've found the null char
  99.  
  100. ;taken out so printat will display $ symbols in game text
  101. ;    cmp    cl,'$'          ;   or a $ - for compatability with DOS
  102. ;    je    exitprintat    ;   string print call.
  103.  
  104.     Push    Ax
  105.     Push    Dx
  106.     Push    Cx
  107.     Call    APutChar    ;   APutChar( Dx, Ax, Cx );
  108.     Pop    Cx
  109.     Pop    Dx
  110.     Pop    Ax
  111.  
  112.     Inc    Si        ;   Pt++;
  113.     Add    Dx,16 ;8        ;   X += 8;
  114. ;    Cmp    Cx,'~'          ;   IF ( ReturnArrow ) THEN
  115. ;    Jne    Norm        ;      BEGIN
  116. ;    Add    Dx,8        ;      X += 8;
  117. ;    Inc    Si        ;      Pt++;
  118.                 ;      END
  119. Norm:    Jmp    SHORT GetCh    ;   END
  120.  
  121. ExitPrintAt:
  122.     Pop    Si
  123.     Ret            ; Return to the caller.
  124.  
  125. PrintAt_ ENDP
  126.  
  127.  
  128. ;************************************************************************
  129. ;* FUNCTION: PutChar( X, Y, Ch )                    *
  130. ;*                                    *
  131. ;* PARAMETERS:                                *
  132. ;*    X  - X position of Character.  0..319 is really 0..79.        *
  133. ;*    Y  - Y position of Character.  0..199                *
  134. ;*    Ch - The character we are to put on the screen.         *
  135. ;*                                    *
  136. ;* DESCRIPTION: Puts the given character on screen.            *
  137. ;************************************************************************
  138.  
  139. CharTable    EQU    0FA6EH        ;Base of graphics character table
  140.                     ;NOTE: hardware dependent
  141.  
  142. PutChar_    PROC    NEAR
  143.  
  144.     Mov    Bx,Sp        ;Set BX to base of parms.
  145.  
  146.     Mov    Dx,2[Bx]    ;Get X
  147.     Mov    Ax,4[Bx]    ;Get Y
  148.     Mov    Cx,6[Bx]    ;Get Char
  149.  
  150. APutChar:
  151. ;    Cmp    Cx,'~'          ;IF ( ReturnArrow ) THEN
  152. ;    Jne    NormCh        ;   DrawSpecial( 3 );
  153. ;    Mov    Cx,3
  154. ;    Call    ADrawSpecial
  155. ;    Ret
  156.  
  157. NormCh: Push    Si        ;Save Registers
  158.     Push    Di
  159.     Push    Es
  160.     Push    Bp
  161.  
  162.     Mov    Di,Ax
  163.     Call    XYCalc_     ;Get offset at which to draw the Char
  164.     Mov    Bp,Di
  165.  
  166.     Mov    Si,Cx        ;Point Si at the char in table
  167.     Shl    Si,1
  168.     Shl    Si,1
  169.     Shl    Si,1
  170.     Add    Si,CharTable
  171.  
  172.     Cld            ;Direction = forward
  173.     Mov    Cx,8        ;8 byte character set
  174.  
  175. NextCharRow:            ;DO
  176.  
  177.     Mov    Di,ds:[Bp]    ;   Get row pointer <-was using ss:!!!
  178.     Add    Di,Dx
  179.  
  180.     Push    Ds
  181.     Mov    Ax,0F000H    ;   Set DS register to the base
  182.     Mov    Ds,Ax        ;   of last memory ROM segment.
  183.     Lodsb            ;   Acquire a byte(pixel map) of the Char
  184.     Pop    Ds
  185.  
  186.     Call    StoreByte    ;   Put the byte in screen memory
  187.  
  188.     Add    Bp,2        ;   END
  189.     Loop    NextCharRow    ;WHILE( --Cx );
  190.  
  191.     Pop    Bp
  192.     Pop    Es
  193.     Pop    Di        ;Save Registers
  194.     Pop    Si
  195.  
  196.     Ret
  197.  
  198. PutChar_    ENDP
  199. ;************************************************************************
  200. ;* FUNCTION: StoreByte                            *
  201. ;*                                    *
  202. ;* PARAMETERS:                                *
  203. ;*  Reg Al - The byte we are to store.                    *
  204. ;*    Es:Di - Points to the screen memory where we are to store byte. *
  205. ;*                                    *
  206. ;* DESCRIPTION: Takes the byte in Al, converts it to a 16 bit value and *
  207. ;*        then masks the color bits to the current 'ColorMask'.   *
  208. ;*        Di is incremented by 2 on exit.             *
  209. ;************************************************************************
  210.  
  211. StoreByte    PROC    NEAR
  212.  
  213.     Call    ExpandByte_    ;Convert to word
  214.     Xchg    Ah,Al
  215.     And    Ax,ColorMask
  216.     Stosw            ;Put the Char into graphics memory
  217.     Ret
  218.  
  219. StoreByte    ENDP
  220.  
  221. ;************************************************************************
  222. ;* FUNCTION: ExpandByte()                        *
  223. ;*                                    *
  224. ;* PARAMETERS:                                *
  225. ;*    TheByte - Byte to be expanded in Al register.            *
  226. ;*                                    *
  227. ;* DESCRIPTION: Expands a byte into a word.                *
  228. ;************************************************************************
  229.  
  230. ExpandByte_    PROC    NEAR
  231.  
  232.     Push    Bx
  233.     Lea    Bx,ExpandTable
  234.     Mov    Ah,Al        ;Save a copy in Ah
  235.     Shr    Al,1        ;a 16 bit character bit map.
  236.     Shr    Al,1
  237.     Shr    Al,1
  238.     Shr    Al,1
  239.     Xlatb            ;Take the 8 bit pattern
  240.     Xchg    Ah,Al        ;and translate it into
  241.     And    Al,00FH
  242.     Xlatb
  243.     Pop    Bx
  244.     Ret
  245.  
  246. ExpandByte_    ENDP
  247. plot        proc    near
  248.         ;
  249.         ;position cursor at locx, locy
  250.         ;
  251.         mov    dh,locy
  252.         mov    dl,locx
  253.  
  254.         cmp    gamevmode,1
  255.         jne    plot_exit
  256.  
  257.         mov    ah,2
  258.         mov    bh,0
  259.         int    10h        ;position on screen
  260.  
  261. plot_exit:    ret
  262.  
  263. plot        endp
  264. char_write    proc    near
  265.         ;
  266.         ;Write char in AL at cursor position for mono
  267.         ;or at position held in dx for graphics.
  268.         ;Used after call to plot.
  269.         ;
  270.         cmp    gamevmode,1
  271.         jne    herc_cga
  272.  
  273.         mov    ah,9
  274.         mov    bh,0
  275.         mov    bl,att_byte
  276.         mov    cx,1
  277.         int    10h
  278.         ret
  279.  
  280. herc_cga:    mov    colormask,0ffffh
  281.         mov    cl,al
  282.         mov    al,dh
  283.         cbw
  284.         xor    dh,dh
  285.         xor    ch,ch
  286.         shl    ax,1
  287.         shl    ax,1
  288.         shl    ax,1
  289.         shl    dx,1
  290.         shl    dx,1
  291.         shl    dx,1
  292.         shl    dx,1
  293.         call    aputchar
  294.         ret
  295. char_write    endp
  296. ;$PAGE
  297. ;************************************************************************
  298. ;* FUNCTION: DoHerc()                            *
  299. ;*                                    *
  300. ;* PARAMETERS:    None                            *
  301. ;*                                    *
  302. ;* DESCRIPTION: Checks to see if the Hercules mono graphics adapter is    *
  303. ;*        there and if it is, it inits it and sets RowTable data    *
  304. ;*        table up accordingly.  Uses vertical rettrace check to    *
  305. ;*        to insure that a card is there.             *
  306. ;*                                    *
  307. ;* RETURNS:    Carry set if card is not there.             *
  308. ;************************************************************************
  309.  
  310. DoHerc        PROC    NEAR
  311.  
  312.     Mov    Dx,03BFH        ;Turn on Herc card
  313.     Mov    Al,00000011B
  314.     Out    Dx,Al
  315.  
  316.     Mov    Bl,OldFlag        ;Get OldFlag
  317.     Push    Ds            ;Restore old equipment flag
  318.     Mov    Ax,EquipSeg
  319.     Mov    Ds,Ax
  320.     Mov    ds:[EquipFlag],Bl
  321.     Pop    Ds
  322.  
  323.     Mov    Dx,3BAH         ;Display status port for Herc
  324.     Mov    Bl,10000000B        ;Vertical retrace mask bit for Herc card
  325.     ;Call    CheckRetrace
  326.     ;Jnc    InitHerc
  327.  
  328.     ;Stc
  329.     ;Ret
  330.  
  331. InitHerc:
  332.  
  333.     Mov    GrAdapterType_,HERCCARD
  334.  
  335.     Push    Si
  336.     Push    Di
  337.  
  338.     Mov    Cx,50            ;Do 50 groups of 4
  339.     Lea    Bx,RowTable        ;Point to table
  340.     Mov    Si,0658H        ;Line 0 + 8 byte offset Screen center
  341.     Mov    Di,2658H        ;Line 1 + 8 byte offset Screen center
  342.     Mov    Ax,4658H        ;Line 2 + 8 byte offset Screen center
  343.     Mov    Dx,6658H        ;Line 3 + 8 byte offset Screen center
  344.  
  345. TLoop1: Mov    [Bx],Si         ;Store 4 words
  346.     Mov    [Bx+2],Di
  347.     Mov    [Bx+4],Ax
  348.     Mov    [Bx+6],Dx
  349.  
  350.     Add    Si,90            ;Add 90 for next line of 4
  351.     Add    Di,90
  352.     Add    Ax,90
  353.     Add    Dx,90
  354.  
  355.     Add    Bx,8            ;Move to next 4 pointers
  356.     Loop    TLoop1            ;Loop for all rows
  357.  
  358.     Call    ClearScreen_
  359.  
  360.     Lea    Si,GTable        ;Ptr to Herc card init table
  361.     Call    SetParams        ;Set the Herc card params.
  362.  
  363.     Mov    Dx,3B8H         ;Set Ctrl Reg for scrn on,
  364.     Mov    Al,10001010B        ;Bit 1 - gr mode, Bit 3 - activate scrn
  365.     Out    Dx,Al            ;Bit 7 - display page B800H
  366.  
  367.     Pop    Di
  368.     Pop    Si
  369.  
  370.     Clc                ;Clear carry to show that herc is there
  371.     Ret
  372.  
  373. SetParams:
  374.     Mov    Dx,3B4H         ;Index register position
  375.     Mov    Cx,12            ;Move 12 parameters to data registers
  376.     Xor    Ah,Ah            ;Start with register 0
  377. Parms:
  378.     Mov    Al,Ah            ;Send reg number to index reg 3B4H
  379.     Out    Dx,Al
  380.  
  381.     Inc    Dx            ;Now send data to data reg 3B5H
  382.     Lodsb
  383.     Out    Dx,Al
  384.  
  385.     Inc    Ah
  386.     Dec    Dx
  387.     Loop    Parms
  388.  
  389.     Ret
  390.  
  391. DoHerc        ENDP
  392. ;$PAGE
  393. ;************************************************************************
  394. ;* FUNCTION: ClearScreen()                        *
  395. ;*                                    *
  396. ;* PARAMETERS:                                *
  397. ;*    None -                                *
  398. ;*                                    *
  399. ;* DESCRIPTION: Clears the graphics screen                *
  400. ;************************************************************************
  401.  
  402. ClearScreen_    PROC    NEAR
  403.  
  404.     Push    Di
  405.     Push    Es
  406.  
  407.     Mov    Es,VideoSeg
  408.  
  409.     Mov    Cx,4000H        ;Word count of entire screen
  410.     Mov    Ax,0            ;Write null pattern to screen
  411.     Mov    Di,Ax            ;Start at screen address 0
  412.     Cld                ;Set direction to forward
  413.     Rep    Stosw            ;Clear screen a word at a time
  414.  
  415.     Pop    Es
  416.     Pop    Di
  417.     Ret
  418.  
  419. ClearScreen_    ENDP
  420. begin    endp
  421. codesg    ends
  422.     end    begin
  423.